<template>

</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
</style>
<script>
import apiBase from "@/api/apiBase.js";
import { ORDER } from "@/const/orderConst.js";

export default {
  name: "staEndUse",
  methods: {
    //功能操作
    open(order, id) {
      this.order = order;
      switch (this.order) {
        case ORDER.START:
          this.dataStart(id);
          break;
        case ORDER.END:
          this.dataEnd(id);
          break;
        default:
      }
    },
    //禁止使用
    dataEnd(id) {
      this.$confirm("此操作将会禁止该数据的使用, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        var data = {
          ID: id
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Status.End,
          res => {
            this.refreshData();
            this.$message({
              message: this.order + res.data.msg,
              type: "success"
            });
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      });
    },
    //开始使用
    dataStart(id) {
      this.$confirm("此操作将会开启该数据的使用, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        var data = {
          ID: id
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Status.Start,
          res => {
            this.refreshData();
            this.$message({
              message: this.order + res.data.msg,
              type: "success"
            });
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      });
    },
    refreshData() {
      this.$emit("refreshData");
    },
  },
  components: {},
  mounted() {},
  created() {}
};
</script>